//
//  DispatchQueue+Extension.swift
//  HinsLive
//
//  Created by haoxian on 2019/4/16.
//  Copyright © 2019 Hins. All rights reserved.
//

import Foundation

extension DispatchQueue {
    static let network      = DispatchQueue(label: "com.hins.network_quque", attributes: .concurrent)
    static let filemanager  = DispatchQueue(label: "com.hins.filemanager_quque")
    static let userDefaults = DispatchQueue(label: "com.hins.userDefaults_quque")
}

extension DispatchQueue {
    static func safeMainSync(_ exectue: @escaping () -> Void) {
        if Thread.isMainThread {
            exectue()
        } else {
            DispatchQueue.main.sync(execute: exectue)
        }
    }
    
    static func safeMainAsync(_ exectue: @escaping () -> Void) {
        if Thread.isMainThread {
            exectue()
        } else {
            DispatchQueue.main.async(execute: exectue)
        }
    }
    
    static func mainDelay(_ deadline: TimeInterval, _ exectue: @escaping () -> Void) {
        DispatchQueue.main.asyncAfter(deadline: .now() + deadline, execute: exectue)
    }
}
